package cn.wolfcode.luowowo2.articleserver.service.imp;

import cn.wolfcode.luowowo2.article.domain.Strategy;
import cn.wolfcode.luowowo2.article.domain.StrategyCatalog;
import cn.wolfcode.luowowo2.article.mapper.StrategyCatalogMapper;
import cn.wolfcode.luowowo2.article.mapper.StrategyMapper;
import cn.wolfcode.luowowo2.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo2.article.service.IStrategyService;
import cn.wolfcode.luowowo2.common.query.StrategyCatalogQueryObject;
import cn.wolfcode.luowowo2.common.query.StrategyQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Albert on 2019/7/9.
 */
@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService{
    @Autowired
    private StrategyCatalogMapper mapper;
    @Override
    public PageInfo<StrategyCatalog> query(StrategyCatalogQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCatalog> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        if (strategyCatalog.getId()==null) {
            mapper.insert(strategyCatalog);
        }else {
            mapper.updateByPrimaryKey(strategyCatalog);
        }
    }

    @Override
    public List<StrategyCatalog> getCatalogByStrategyId(Long strategyId) {
        return mapper.selectCatalogByStrategyId(strategyId);
    }
}
